package com.yanqu.road.server.manger.activity.snowgarden.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.pb.activity.ServerMallBuyProto;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.server.game.service.IGameServiceCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.snowgarden.ActivityMallDayBuyMgr;
import com.yanqu.road.server.manger.activity.snowgarden.MallDayBuyActivity;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.sync.message.SyncResponse;

public class ActivityMallDayBuyAutoRewardServiceCmd implements IGameServiceCommand {
    @Override
    public SyncResponse execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        SyncResponse syncResponse = new SyncResponse();
        ServerMallBuyProto.CrossMallBuyToServerSyncMsg syncMsg = ServerMallBuyProto.CrossMallBuyToServerSyncMsg.parseFrom(request.getDataBytes());

        MallDayBuyActivity activity = ActivityMallDayBuyMgr.getActivity(syncMsg.getActivityId());
        if (activity == null) {
            ActivityMallDayBuyMgr.getLogger().error("ActivityMallDayBuyAutoRewardServiceCmd execute error, activity is null, activityId:{}", syncMsg.getActivityId());
        } else {
            activity.autoReward(syncMsg.getCrossBuyDataList());
        }

        for (GamePlayer onlinePlayer : GamePlayerMgr.getAllOnlinePlayer()) {
            onlinePlayer.notifyListener(eGamePlayerEventType.SeasonServerMallBuyTask.getValue());
        }


        return syncResponse;
    }
}
